
/**
 * User: hadoop
 * Date: 2014/10/10 0010
 * Time: 18:59
 */
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._

/**
 * 统计字符出现次数
 */
object WordCount {
  def main(args: Array[String]): Unit = {
    val wordFile = "C:\\Users\\KC\\Desktop\\即饮咖啡.txt"
    val conf = new SparkConf().setAppName("wordcount").setMaster("local");
    val sc = new SparkContext(conf)
    val input = sc.textFile(wordFile, 2).cache()
    val lines = input.flatMap(line=>line.split(" "))
    val count = lines.map(word => (word,1)).reduceByKey{case (x,y)=>x+y}
    count.foreach(println)
//    val output = count.saveAsTextFile("/home/hadoop/hellospark")
  }
}
